package com.xiaoyi.service.impl;

import com.google.gson.Gson;
import com.xiaoyi.dao.OrderInfoDao;
import com.xiaoyi.dao.impl.OrderInfoDaoImpl;
import com.xiaoyi.entity.BusinessInfo;
import com.xiaoyi.entity.RespBean;
import com.xiaoyi.service.OrderInfoService;

import javax.servlet.http.HttpServletRequest;

public class OrderInfoServiceImpl implements OrderInfoService {
    private OrderInfoDao orderInfoDao=new OrderInfoDaoImpl();
    @Override
    public String takeOrder(HttpServletRequest req) {
        RespBean respBean=null;
        //从session中获取登录信息
        BusinessInfo businessInfo=(BusinessInfo)req.getSession().getAttribute("businessInfo");
        //获取请求参数--->订单编号
        Integer orderId =Integer.parseInt(req.getParameter("orderId"));
        //调用dao修改订单状态
        int count=orderInfoDao.updateOrderForStatus(orderId,businessInfo.getId(),2);
        if(count>0){
            respBean=RespBean.success();
        }else {
            respBean=RespBean.error(10010,"修改订单状态失败");
        }
        Gson gson=new Gson();
        return gson.toJson(respBean);
    }
}
